package com.example.smartcitymovie.ui.movie;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SearchView;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.widget.LinearLayout;

import com.example.smartcitymovie.MyApplication;
import com.example.smartcitymovie.R;
import com.example.smartcitymovie.bean.LocalAddressBean;
import com.example.smartcitymovie.bean.PreviewMovieBean;
import com.example.smartcitymovie.bean.PreviewMovieListBean;
import com.example.smartcitymovie.dataRepo.ApiData;
import com.example.smartcitymovie.databinding.ActivityPreviewMovieBinding;
import com.example.smartcitymovie.utils.OkHttpUtils;
import com.google.gson.Gson;

import java.io.IOException;

import cn.hutool.core.bean.BeanUtil;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

public class PreviewMovieActivity extends AppCompatActivity {

    ActivityPreviewMovieBinding binding;
    private PreviewMovieBean previewMovieBean;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityPreviewMovieBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        getSupportActionBar().setTitle("影片预告");
        initView();
    }

    private void initView() {
        PreviewMovieListBean previewMovieListBean = ApiData.getPreviewMovieListBean();
        previewMovieBean = BeanUtil.toBean(previewMovieListBean, PreviewMovieBean.class);
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                    binding.RVPreviewMovies.setLinearLayoutManager(LinearLayout.VERTICAL);
                    binding.RVPreviewMovies.setAdapter(previewMovieBean.getRows(),R.layout.preview_list_item_layout);
                    binding.RVPreviewMovies.getBaseAdapter().setOnRecycleViewItemCLickListener((view, position) -> {
                        Intent intent = new Intent(PreviewMovieActivity.this,PreviewMovie.class);
                        intent.putExtra("id",previewMovieBean.getRows().get(position).getId());
                        startActivity(intent);
                    });
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.adress_menu,menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        menu.findItem(R.id.address_menu).setTitle("大连");
        return super.onPrepareOptionsMenu(menu);
    }
}